#!/bin/bash
prefix=$(date +%Y%m%d%H%M%S)
for loop in "psn-blog" "test"
do
    filename="$loop-$prefix"
    /usr/local/bin/docker exec mysql8 sh -c "mysqldump -uroot $loop > /var/lib/mysql/backup/$filename.sql"
    if [ $? -eq 0 ];then
        echo $filename"  done"
    else
        echo $filename"  failed"
        exit 1
    fi
done
# !!! 注意上面一定要使用绝对路径